package com.tongcheng.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.tongcheng.ResultDate;
import com.tongcheng.commons.Contants;
import com.tongcheng.feign.UserCouponsseviceFeign;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

@Service
public class UserCouponssevice implements UserCouponsseviceFeign {
    @Autowired(required = false)
    private UserCouponsseviceFeign userCouponsseviceFeign;

    @HystrixCommand(fallbackMethod = "checkError")
    public ResultDate userReceiveCoupons(@RequestParam(value ="userId") Integer userId, @RequestParam(value ="coupons_id") Integer coupons_id) {
        return userCouponsseviceFeign.userReceiveCoupons(userId,coupons_id);
    }


    @HystrixCommand(fallbackMethod = "checkError2")
    public ResultDate userSeeCoupons(Integer userId){
        return userCouponsseviceFeign.userSeeCoupons(userId);
    }

    @HystrixCommand(fallbackMethod = "checkError3")
    public ResultDate merchantSeeCoupons(Long merchant_id){
        return userCouponsseviceFeign.merchantSeeCoupons(merchant_id);
    }
    @HystrixCommand(fallbackMethod = "checkError4")
    public ResultDate merchantReceiveCoupons(@RequestParam(value = "merchant_id")Long merchant_id,@RequestParam(value = "coupons_id") Integer coupons_id){
        return userCouponsseviceFeign.merchantReceiveCoupons(merchant_id,coupons_id);
    }

    public ResultDate checkError(@RequestParam(value ="userId") Integer userId, @RequestParam(value ="coupons_id") Integer coupons_id) {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
    public ResultDate checkError2(Integer userId) {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
    public ResultDate checkError3(Long merchant_id) {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
    public ResultDate checkError4(@RequestParam(value = "merchant_id")Long merchant_id,@RequestParam(value = "coupons_id") Integer coupons_id) {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
}
